home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / cputype.zip / CPU.ASM next >
Assembly Source File  |  1993-04-01  |  5KB  |  134 lines

  1. ;
  2. ; From the book "Using Assembly Language"
  3. ;               Allen L. Wyatt, Sr.
  4. ;               3rd Edition
  5. ;               QUE Corporation
  6. ;               Libraray of Congress Number: 92-80083
  7. ;               ISBN Number:                 0-88022-884-9
  8. ;               $29.95, US
  9. ;               $37.95, CAN
  10. ;               From Page 358-363
  11. ;
  12. ;
  13. ; Callable from C as:    int cpu()
  14. ;
  15. ; Return Values:   86  =    8086 processor
  16. ;                  88  =    8088 processor
  17. ;                 186  =   80186 processor
  18. ;                 188  =   80188 processor
  19. ;                 286  =   80286 processor
  20. ;                 386  =   80386 processor
  21. ;                 486  =   80486 processor
  22. ;
  23. ;
  24. ;
  25.  
  26.           PUBLIC _cpu
  27.  
  28.           .MODEL small, C
  29.  
  30.           .DATA
  31.  
  32. CPUType   dw   0000h
  33. TestInst  db     43h
  34.  
  35.           .CODE
  36.  
  37. _cpu      proc  near
  38.  
  39.           pushf                         ; original flags
  40.           pop   ax                      ; into a workable variable
  41.           and   ax, 3fffh               ; turn-off bits 14, 15
  42.           push  ax
  43.           popf                          ; put in proper register
  44.           pushf                         ; store flags
  45.           pop   ax                      ; get back flags to examine
  46.           and   ax, 0c000h              ; only interested in bits 15, 16
  47.           cmp   ax, 0                   ; have they been cleared
  48.           je    I286_1                  ; if so, it's at least a 286
  49.  
  50.           mov   cl, 21h
  51.           mov   al, 0ffh
  52.           shr   al, cl                  ; if AL not clear, it's an 80186 or 80188
  53.           cmp   al, 0
  54.           mov   ax, 188                 ; assume it's an 80188
  55.  
  56.           jne   DoBuss                  ; flag still set from previous CMP
  57.  
  58.           mov   ax, 88                  ; assume it's an 8088
  59.  
  60. DoBuss:   CALL  TestQueue               ; chack the Buss width
  61.  
  62.           sub   ax, bx                  ; BX is 0 if 188 else BX is 2
  63.           mov   CPUType, ax
  64.           jmp   Exit
  65.  
  66. ; at this point the processor is a 286, 386 or 486
  67.  
  68. I286_1:   pushf
  69.           pop    ax
  70.           or     ax, 4000h               ; set bit 4 (NT flag)
  71.           push   ax
  72.           popf                           ; flag bit 14 is now set
  73.           pushf                          ; store flags
  74.           pop    ax                      ; get flags back to examine
  75.           and    ax, 4000h               ; only care about bit 14
  76.           cmp    ax, 4000h               ; is it still set?
  77.           je     I386_1                  ; if so, it's at least a 386
  78.           mov    CPUType, 286            ; else it's a 286
  79.           jmp    Exit
  80.  
  81. ; at this point we know it is a 32-bit processor
  82.  
  83.           .386                           ; enable 386 assembly
  84. I386_1:   pushfd                         ; push extended flags
  85.           pop    eax                     ; get back to work with
  86.           mov    ebx, eax                ; store a copy
  87.           and    ebx, 40000h             ; only care about bit 18 (AC flag)
  88.           xor    eax, 40000h             ; toggle AC flag (bit 18)
  89.           push   eax                     ; stuff adjusted flag register
  90.           popfd                          ; put it in the proper place
  91.           pushfd                         ; push it again
  92.           pop    eax                     ; get it back to examine
  93.           and    eax, 40000h             ; want to look at bit 18 (AC flag)
  94.           mov    CPUType, 386            ; assume it's a 386
  95.           cmp    eax, ebx                ; if same, it's a 386
  96.           je     Exit
  97.  
  98.           pushfd                         ; must be a 486
  99.           pop    eax                     ; move to work on
  100.           xor    eax, 40000h             ; toggle AC flag
  101.           push   eax
  102.           popfd
  103.           mov    CPUType, 486
  104.  
  105.           .8086
  106. Exit:     mov    ax, CPUType
  107.  
  108.           ret
  109.  
  110. _cpu      endp
  111.  
  112.  
  113.  
  114.  
  115. TestQueue proc
  116.  
  117.           USES   ax
  118.  
  119.           mov    bx, 1
  120.           mov    al, TestInst            ; Load opcode for INC BX
  121.           xor    al, 8                   ; change INC BX to DEC BX
  122.           mov    TestInst, al            ; move it back to proper place
  123.           nop                            ; If using an 8-bit data bus,
  124.           nop                            ;    the following 4 NOPs will
  125.           nop                            ;    fill the queue, allowing the
  126.           nop                            ;    next bytes to be changed
  127.  
  128.           ret
  129.  
  130. TestQueue endp
  131.  
  132.           end
  133.  
  134.